<template>
    <div>
        <Alert/>
        <page-header title="图标"/>
        <page-main class="demo">
            <i class="el-icon-edit"/>
            <i class="el-icon-share"/>
            <i class="el-icon-delete"/>
            <el-button type="primary" icon="el-icon-search">搜索</el-button>
        </page-main>
        <page-main title="图标集合">
            <div v-for="(item, index) in icon" :key="index" class="list-icon">
                <el-tooltip class="item" effect="dark" :content="`el-icon-${item}`" placement="top">
                    <i :class="`el-icon-${item}`"/>
                </el-tooltip>
            </div>
        </page-main>
        <page-main title="自定义图标">
            <div v-for="(item, index) in anpassenIcons" :key="index" class="list-icon">
                <el-tooltip class="item" effect="dark" :content="`${item}`" placement="top">
                    <svg-icon :icon-class="`${item}`"/>
                </el-tooltip>
            </div>
        </page-main>
    </div>
</template>

<script>
import Alert from './components/alert.vue'
import icon from './icon.json'

export default {
    components: {
        Alert
    },
    data() {
        return {
            anpassenIcons: []
        }
    },
    computed: {
        icon() {
            return icon
        }
    },
    mounted() {
        this.getAnpassenIcon()
    },
    methods: {
        /**
         * @desc : 获取自定义ICON
         * @author : 刘尧
         * @date : 2024/12/19 14:10
         */
        getAnpassenIcon() {
            const files = require.context("@/assets/icons/svg", true, /\.svg$/).keys();
            const newIcons = files.map(file => file.replace("./", "").replace(".svg", ""))
            this.anpassenIcons = newIcons
        }
    }
}
</script>

<style lang="scss" scoped>
.demo {
    i {
        color: #606266;
        margin: 0 20px;
        font-size: 1.5em;
        vertical-align: middle;
    }

    button {
        margin: 0 20px;
    }
}

.list-icon {
    display: inline-block;
    font-size: 32px;
    color: #606266;
    margin: 10px;
}
</style>
